<%@page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="info" class="top.zerozoo.learn.grade.vo.StudentListInfo" scope="request"/>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>学生成绩管理系统 - 学生管理</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/global.css">
    <script src="js/jquery-2.1.0.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">学生管理</h3>
    <div class="action-bar clearfix mb10 mt20">
        <div class="fl">
            <form class="form-inline" id="form-search" action="${pageContext.request.contextPath}/studentList.do"
                  method="get">
                <div class="form-group">
                    <label for="name">姓名</label>
                    <input type="text" class="form-control" id="name" name="name"
                           value="${info.condition.name}">
                </div>
                <div class="form-group">
                    <label for="major">专业</label>
                    <select class="form-control" id="major" name="major">
                        <option value=""></option>
                        <c:forEach items="${info.majors}" var="item" varStatus="status">
                            <c:if test="${item.name == info.condition.major}">
                                <option selected value="${item.name}">${item.name}</option>
                            </c:if>
                            <c:if test="${item.name != info.condition.major}">
                                <option value="${item.name}">${item.name}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </div>
                <button type="submit" class="btn btn-default">查询</button>
            </form>
        </div>
        <div class="fr mr5">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/studentAdd.do">添加学生</a>
            <a class="btn btn-danger" href="javascript:removeSelectedUser()">删除选中</a>
        </div>
    </div>
    <form id="form-remove" action="${pageContext.request.contextPath}/studentRemove.do" method="post">
        <table class="table table-bordered table-hover">
            <tr class="success">
                <th><input type="checkbox" id="checkbox-all"></th>
                <th>序号</th>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>专业</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${info.pageInfo.list}" var="item" varStatus="status">
                <tr>
                    <td><input type="checkbox" class="checkbox-user" name="id" value="${item.id}"></td>
                    <td>${status.count}</td>
                    <td>${item.id}</td>
                    <td>${item.name}</td>
                    <td>${empty item.sex ? "无":item.sex}</td>
                    <td>${empty item.age ? "无":item.age}</td>
                    <td>${empty item.major ? "无":item.major}</td>
                    <td>
                        <a class="btn btn-default btn-sm" href="studentDetail.do?id=${item.id}">详情</a>
                        <a class="btn btn-default btn-sm" href="javascript:removeUser(${item.id})">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>

    <nav aria-label="Search results pages">
        <ul class="pagination">
            <c:if test="${info.pageInfo.currentPage == 1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${info.pageInfo.currentPage != 1}">
                <li>
                    <a href="${pageContext.request.contextPath}/studentList.do?currentPage=${info.pageInfo.currentPage-1}&rows=20&name=${info.condition.name}&major=${info.condition.major}"
                       aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:forEach begin="1" end="${info.pageInfo.totalPage}" step="1" var="i">
                <c:if test="${info.pageInfo.currentPage == i}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${info.pageInfo.currentPage != i}">
                    <li>
                        <a href="${pageContext.request.contextPath}/studentList.do?currentPage=${i}&rows=20&name=${info.condition.name}&major=${info.condition.major}">${i}</a>
                    </li>
                </c:if>

            </c:forEach>
            <c:if test="${info.pageInfo.currentPage == info.pageInfo.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${info.pageInfo.currentPage != info.pageInfo.totalPage}">
                <li>
                    <a href="${pageContext.request.contextPath}/studentList.do?currentPage=${info.pageInfo.currentPage+1}&rows=20&name=${info.condition.name}&major=${info.condition.major}"
                       aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
        </ul>
    </nav>
    <p class="f24 ml10 mb30">共${info.pageInfo.totalCount}条记录，${info.pageInfo.totalPage}页</p>
</div>
<script>
    $(function () {
        $("#checkbox-all").click(function () {
            $(".checkbox-user").each(function () {
                $(this)[0].checked = $("#checkbox-all")[0].checked
            })
        })
    })

    function removeUser(id) {
        if (confirm("确定要删除吗？")) {
            $.ajax({
                url: '${pageContext.request.contextPath}/studentRemove.do',
                type: 'post',
                data: {id: id},
                complete: function () {
                    location.reload()
                }
            })
        }
    }

    function removeSelectedUser() {
        if (confirm("确定要删除吗？")) {
            $("#form-remove")[0].submit()
        }
    }
</script>
</body>
</html>
